home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Magnum One
/
Magnum One (Mid-American Digital) (Disc Manufacturing).iso
/
d12
/
tde11.arc
/
TDECOLOR.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-09-06
|
19KB
|
661 lines
/*
* I have had several requests to implement a method for changing the colors
* used in tde. I thought about using a configuration file, but I really
* didn't like that route. Changing the executable file seemed the best way
* to go. That way, you only need one file to run tde - the executable.
* Also, I didn't have to add a bunch of code to tde to parse a configuration
* file. It doesn't take a lot of time to figure out the offsets of the those
* variables to initialize in tde.exe, so it's fairly easy to do.
*
* Program name: tdecolor
* Author: Frank Davis
* Date: July 21, 1991
* Compiler: MSC 6.0a and QuickC 2.5
* cl /AS /Gs tdecolor.c
* exehdr /max:1000 tdecolor
*
* This program is released into the public domain. You may distribute
* it freely, Frank Davis
*/
/******** EXTREMELY IMPORTANT ************/
/*
* If you modify tde, it is your responsibility to find the offset of
* "static int colors" in function "hw_initialize" in file "main.c" in your
* new executable, tde.exe.
*
* If you don't change the default colors, search for the following string (a
* hexadecimal integer array) in your new executable file:
*
* 7000 0700 7000 7000 0f00 0700 7000 4b00 0700 1700 7f00 0f00 1a00 1a00
*
* Then, replace COLOR_OFFSET with your new one and recompile tdecolor.exe
* with the new offset.
*/
#define COLOR_OFFSET 56329l
/******* EXTREMELY IMPORTANT ************/
#include <bios.h>
#include <dos.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "tdecolor.h"
/********************** prototypes ********************************/
void xygoto( int, int );
void initialize( void );
void video_config( void );
void show_init_sample( void );
void color_number( char *, int );
void current_color_number( char *, int );
int getkey( void );
void s_output( char far *, int, int, int );
void cls( void );
void hlight_line( int, int, int, int );
void show_help_color( );
void show_fileheader_color( );
void show_text_color( );
void show_block_color( );
void show_warning_color( );
void show_mode_color( );
void show_wrapped_color( );
void change_colors( void );
/********************************************************************/
char *greatest_composer_ever = "W. A. Mozart, 1756-1791";
/*
* Default color settings. Incidentally, I'm color blind (mild red-green) and
* the default colors look fine to me. ;*)
*/
static int colors[2][7] = {
{ HERC_REVERSE, HERC_NORMAL, HERC_REVERSE, HERC_REVERSE, HERC_HIGH,
HERC_NORMAL, HERC_REVERSE },
{ COLOR_HEAD, COLOR_TEXT, COLOR_MODE, COLOR_BLOCK, COLOR_MESSAGE,
COLOR_HELP, COLOR_WRAP }
};
static int temp_colors[2][7]; /* play around with colors in this array */
struct vcfg cfg; /* video stuff */
static int index; /* 0 = Monochrome colors, 1 = color colors */
FILE *tde_exe; /* FILE pointer to tde.exe */
/*
* Name: main
* Date: July 21, 1991
* Notes: Strategy is fairly straight forward - 1) initialize all the
* variables 2) show the user a color sample 3) make the changes
* permanent if desired.
*/
main( )
{
initialize( );
cls( );
show_init_sample( );
change_colors( );
}
/*
* Name: xygoto
* Date: July 21, 1991
* Notes: Use the video interrupt to set the cursor.
*/
void xygoto( int x, int y )
{
union REGS inregs, outregs;
inregs.h.ah = 2;
inregs.h.bh = 0;
inregs.h.dh = y;
inregs.h.dl = x;
int86( VIDEO_INT, &inregs, &outregs );
}
/*
* Name: initialize
* Date: July 21, 1991
* Notes: Open tde.exe if we can find it. Set up all of the global variables.
*/
void initialize( )
{
int i, j;
video_config( );
if ((tde_exe = fopen( "tde.exe", "r+b" )) == NULL ) {
cls( );
s_output( "Cannot find tde.exe", 0, 0, 7 );
xygoto( 0, 1 );
exit( 1 );
}
fseek( tde_exe, COLOR_OFFSET, SEEK_SET );
fread( (void *)temp_colors, sizeof( temp_colors ), 1, tde_exe );
if (cfg.color == FALSE)
index = 0;
else
index = 1;
fields[0].color = temp_colors[index][HELP];
fields[1].color = temp_colors[index][HEAD];
fields[2].color = temp_colors[index][TEXT];
fields[3].color = temp_colors[index][BLOCK];
fields[4].color = temp_colors[index][WARNING];
fields[5].color = temp_colors[index][MODE];
fields[6].color = temp_colors[index][WRAP];
fields[0].show_me = show_help_color;
fields[1].show_me = show_fileheader_color;
fields[2].show_me = show_text_color;
fields[3].show_me = show_block_color;
fields[4].show_me = show_warning_color;
fields[5].show_me = show_mode_color;
fields[6].show_me = show_wrapped_color;
}
/*
* Name: initialize
* Date: July 21, 1991
* Notes: See main.c for more info
*/
void video_config( )
{
#pragma pack( 1 ) /* Use pragma to force packing on byte boundaries. */
struct LOWMEMVID
{
char vidmode; /* 0x449 */
unsigned scrwid; /* 0x44A */
unsigned scrlen; /* 0x44C */
unsigned scroff; /* 0x44E */
struct LOCATE
{
unsigned char col;
unsigned char row;
} csrpos[8]; /* 0x450 */
struct CURSIZE
{
unsigned char end;
unsigned char start;
} csrsize; /* 0x460 */
char page; /* 0x462 */
unsigned addr_6845; /* 0x463 */
char crt_mode_set; /* 0x465 */
char crt_palette[30]; /* 0x466 */
char rows; /* 0x484 */
unsigned points; /* 0x485 */
char ega_info; /* 0x487 */
char info_3; /* 0x488 */
} vid;
struct LOWMEMVID _far *pvid = &vid;
#pragma pack( ) /* revert to previously defined pack pragma. */
union REGS in, out;
unsigned char temp, active_display;
/* Move system information into uninitialized structure variable. */
movedata( 0, 0x449, FP_SEG( pvid ), FP_OFF( pvid ), sizeof( vid ) );
cfg.rescan = FALSE;
in.x.ax = 0x1a00;
int86( VIDEO_INT, &in, &out );
temp = out.h.al;
active_display = out.h.bl;
if (temp == 0x1a && (active_display == 7 || active_display == 8))
cfg.adapter = VGA;
else {
in.h.ah = 0x12;
in.h.bl = 0x10;
int86( VIDEO_INT, &in, &out );
if (out.h.bl != 0x10) { /* EGA */
if (vid.ega_info & 0x08) {
if (vid.addr_6845 == 0x3d4)
cfg.adapter = CGA;
else
cfg.adapter = MDA;
} else
cfg.adapter = EGA;
} else if (vid.addr_6845 == 0x3d4)
cfg.adapter = CGA;
else
cfg.adapter = MDA;
}
if (cfg.adapter == CGA)
cfg.rescan = TRUE;
cfg.mode = vid.vidmode;
if (vid.addr_6845 == 0x3D4) {
cfg.color = TRUE;
FP_SEG( cfg.videomem ) = 0xb800;
} else {
cfg.color = FALSE;
FP_SEG( cfg.videomem ) = 0xb000;
}
FP_OFF( cfg.videomem ) = 0x0000;
}
/*
* Name: initialize
* Date: July 21, 1991
* Notes: Draw all of the sample screens.
*/
void show_init_sample( )
{
char *sample;
int line, i, j, k, l;
char temp[6], num[6];
char far *p;
xygoto( -1, -1 );
sample = sample_screen[0];
for (line=0; sample != NULL; ) {
s_output( (char far *)sample, line, 0, 7 );
sample = sample_screen[++line];
}
for (i=0; i<7; i++)
(*fields[i].show_me)();
sample = field_screen[0];
for (line=12, i=1; sample != NULL; line++,i++) {
s_output( (char far *)sample, line, 0, 7 );
sample = field_screen[i];
}
p = (char far *)temp;
for (i=0,k=0,line=17; i<8; i++, line++) {
for (j=0,l=0; j<16; j++, k++,l+=5) {
color_number( temp, k );
s_output( p, line, l, k );
}
}
for (i=0; i<7; i++) {
color_number( temp, fields[i].color );
s_output( p, fields[i].line, fields[i].col, fields[i].color );
}
}
/*
* Name: color_number
* Date: July 21, 1991
* Passed: dest: buffer to store the color sample
* num: attribute number
* Notes: Show the use what the foreground and background colors look like.
*/
void color_number( dest, num )
char *dest;
int num;
{
int i, j, k;
char temp[6];
strcpy( dest, "[ ]" );
itoa( num, temp, 10 );
i = strlen( temp );
j = 4 - i;
for (k=0; i > 0; i--,j++, k++)
dest[j] = temp[k];
}
/*
* Name: current_color_number
* Date: July 21, 1991
* Passed: dest: buffer to store the color sample
* num: attribute number
* Notes: Put '*' around the sample color to give the user an idea of where
* the current field is.
*/
void current_color_number( dest, num )
char *dest;
int num;
{
int i, j, k;
char temp[6];
strcpy( dest, "* *" );
itoa( num, temp, 10 );
i = strlen( temp );
j = 4 - i;
for (k=0; i > 0; i--,j++, k++)
dest[j] = temp[k];
}
/*
* Name: getkey
* Date: July 21, 1991
* Notes: Return the key pressed by the user.
*/
int getkey( void )
{
unsigned key, lo, scan;
/*
* _bios_keybrd == int 16. It returns the scan code in ah, hi part of key,
* and the ascii key code in al, lo part of key.
*/
key = _bios_keybrd( 0 );
lo = key & 0X00FF;
lo = (int)((lo == 0) ? (((key & 0XFF00) >> 8) + 256) : lo);
return( lo );
}
/*
* Name: s_output
* Date: July 21, 1991
* Passed: s: the string to display
* line: line number to begin display
* col: column number to begin display
* attr: color to display string
* Notes: See tdeasm.c for more info
*/
void s_output( s, line, col, attr )
char far *s;
int line, col, attr;
{
int far *screen_ptr;
int max_col;
int off;
max_col = 80;
screen_ptr = cfg.videomem;
off = line * 160 + col * 2;
_asm {
push ds ; MUST save ds
push di ; save di on stack
push si ; save si on stack
mov bx, WORD PTR attr ; keep attribute in bx
mov cx, WORD PTR col ; put cols in cx
mov dx, WORD PTR max_col ; keep max_col in dx
mov di, WORD PTR screen_ptr ; load offset of screen ptr
add di, WORD PTR off
mov ax, WORD PTR screen_ptr+2 ; load segment of screen ptr
mov es, ax
mov si, WORD PTR s ; load offset of string ptr
or si, si ; is it == NULL?
je getout ; yes, no output needed
mov ax, WORD PTR s+2 ; load segment of string ptr
or ax, ax ; is pointer == NULL?
je getout ; yes, no output needed
mov ds, ax ; load segment of text in ds
mov ah, bl ; put attribute in AH
top:
cmp cx, dx ; col < max_cols?
jge getout ; no, thru with line
lodsb ; get next char in string - put in al
or al, al ; is it '\0'
je getout ; yes, end of string
stosw ; else show attr + char on screen (ah + al)
inc cx ; col++
jmp SHORT top ; get another character
getout:
pop si ; get back si
pop di ; get back di
pop ds ; get back ds
}
}
/*
* Name: cls
* Date: July 21, 1991
* Notes: Use bios to clear screen (video interrupt).
*/
void cls( )
{
int line;
line = 24;
_asm {
xor ch, ch ; starting row in ch = 0
xor cl, cl ; starting column in cl = 0
mov ax, WORD PTR line ; get ending row
mov dh, al ; put it in dh
mov dl, 79 ; ending column in dl = 79
mov bh, 7 ; attribute in bh = 7 (normal)
mov al, 0 ; get number of lines
mov ah, 6 ; get function number
push bp ; some dos versions wipe out bp
int VIDEO_INT
pop bp
}
}
/*
* Name: hlight_line
* Date: July 21, 1991
* Passed: x: column to begin hi lite
* y: line to begin hi lite
* lgth: number of characters to hi lite
* attr: attribute color
* Notes: The attribute byte is the hi byte.
*/
void hlight_line( x, y, lgth, attr )
int x, y, lgth, attr;
{
int off, far *pointer;
pointer = cfg.videomem;
off = y * 160 + 2 * x + 1; /* add one - so it points to attribute byte */
_asm {
push di ; save es
mov cx, lgth ; number of characters to change color
mov di, WORD PTR pointer ; get destination - video memory
add di, off ; add offset
mov ax, WORD PTR pointer+2 ;
mov es, ax
mov ax, attr ; attribute
lite_len:
stosb ; store a BYTE
inc di ; skip over character to next attribute
loop lite_len ; change next attribute
pop di ; restore di
}
}
/*
* Name: show_help_color
* Date: July 21, 1991
*/
void show_help_color( )
{
int color;
int line, len;
color = fields[0].color;
for (line=1; line <11; line++)
hlight_line( 1, line, 37, color );
}
/*
* Name: show_fileheader_color
* Date: July 21, 1991
*/
void show_fileheader_color( )
{
hlight_line( 41, 1, 38, fields[1].color );
}
/*
* Name: show_text_color
* Date: July 21, 1991
*/
void show_text_color( )
{
int color;
int line, len;
color = fields[2].color;
for (line=2; line <6; line++)
hlight_line( 41, line, 38, color );
}
/*
* Name: show_block_color
* Date: July 21, 1991
*/
void show_block_color( )
{
int color;
int line, len;
color = fields[3].color;
for (line=6; line <9; line++)
hlight_line( 41, line, 38, color );
}
/*
* Name: show_warning_color
* Date: July 21, 1991
*/
void show_warning_color( )
{
hlight_line( 41, 9, 38, fields[4].color );
}
/*
* Name: show_mode_color
* Date: July 21, 1991
*/
void show_mode_color( )
{
hlight_line( 41, 10, 26, fields[5].color );
}
/*
* Name: show_wrapped_color
* Date: July 21, 1991
*/
void show_wrapped_color( )
{
hlight_line( 67, 10, 12, fields[6].color );
}
/*
* Name: change_colors
* Date: July 21, 1991
* Notes: Real workhorse function of the utility. Get a key and then
* figure out what to do with it.
*/
void change_colors( )
{
int c;
int area;
int color;
int new_color;
int i;
char temp[6];
char far *p;
p = (char far *)temp;
area = 0;
current_color_number( temp, fields[area].color );
s_output( p, fields[area].line, fields[area].col, fields[area].color );
xygoto( fields[area].col+3, fields[area].line );
for (c=0; c != F3 && c != F10 && c != ESC;) {
new_color = FALSE;
c = getkey( );
switch (c) {
case RTURN :
color_number( temp, fields[area].color );
s_output( p, fields[area].line, fields[area].col, fields[area].color );
++area;
if (area > 6)
area = 0;
current_color_number( temp, fields[area].color );
s_output( p, fields[area].line, fields[area].col, fields[area].color );
xygoto( fields[area].col+3, fields[area].line );
break;
case UP :
--fields[area].color;
if (fields[area].color < 0)
fields[area].color = 127;
new_color = TRUE;
break;
case DOWN :
++fields[area].color;
if (fields[area].color > 127)
fields[area].color = 0;
new_color = TRUE;
break;
case PGUP :
fields[area].color -= 16;
if (fields[area].color < 0)
fields[area].color = (fields[area].color & 0x000f) + 0x70;
new_color = TRUE;
break;
case PGDN :
fields[area].color += 16;
if (fields[area].color > 127)
fields[area].color = fields[area].color & 0x000f;
new_color = TRUE;
break;
case F2 :
fields[0].color = colors[index][HELP];
fields[1].color = colors[index][HEAD];
fields[2].color = colors[index][TEXT];
fields[3].color = colors[index][BLOCK];
fields[4].color = colors[index][WARNING];
fields[5].color = colors[index][MODE];
fields[6].color = colors[index][WRAP];
for (i=0; i<7; i++) {
color_number( temp, fields[i].color );
s_output( p, fields[i].line, fields[i].col, fields[i].color );
(*fields[i].show_me)();
}
current_color_number( temp, fields[area].color );
s_output( p, fields[area].line, fields[area].col, fields[area].color );
break;
}
if (new_color) {
current_color_number( temp, fields[area].color );
s_output( p, fields[area].line, fields[area].col, fields[area].color );
(*fields[area].show_me)();
}
}
if (c == F10) {
temp_colors[index][HELP] = fields[0].color;
temp_colors[index][HEAD] = fields[1].color;
temp_colors[index][TEXT] = fields[2].color;
temp_colors[index][BLOCK] = fields[3].color;
temp_colors[index][WARNING] = fields[4].color;
temp_colors[index][MODE] = fields[5].color;
temp_colors[index][WRAP] = fields[6].color;
fseek( tde_exe, COLOR_OFFSET, SEEK_SET );
fwrite( (void *)temp_colors, sizeof( temp_colors ), 1, tde_exe );
}
fseek( tde_exe, 0l, SEEK_END );
fcloseall( );
cls( );
xygoto( 0, 0 );
}